﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
using System.Data;
using System.Xml;


namespace MODULE_TIENICH
{
    public class cls_tienich
    {
        private tienichDataContext ccontext = new tienichDataContext(getconnectstring());
        public static tienichDataContext getcontext()
        {
            return new tienichDataContext(getconnectstring());
        }
        private bool ispass = false;
        public bool getsetispass
        {
            get { return ispass; }
            set { ispass = value; }
        }
        private string strongluong;
        public string trongluong
        {
            get { return strongluong; }
            set { strongluong = value; }
        }
        private string  makhachhang;
        public string _makhachhang
        {
            get { return makhachhang; }
           // set { makhachhang = value; }
        }
        private string manv;
        public string _manv
        {
            get { return manv; }
        }
        private string mahanghoa;
        public string _mahanghoa
        {
            get { return mahanghoa; }
            set { mahanghoa = value; }

        }
        public static string getconnectstring()
        {
            string kq = "";
            XmlDocument MyDoc = new XmlDocument();

            MyDoc.Load("extension\\extension.xml");
            XmlNode root = (XmlNode)MyDoc.DocumentElement;

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlNode element = (XmlNode)root.ChildNodes[i];
                if (element.Name == "connection")
                {
                    kq = element.Attributes["connectionString"].Value.ToString();
                }
            }
            return kq;

        }
        public void ShowForm(string formname)
        {
            
            switch (formname)
            {
                case "frm_report":
                    frm_report frmrp = new frm_report();
                    frmrp.Show();
                    
                    break;
                case "frm_timkiemchuhang":
                    frm_timkiemchuhang tk = new frm_timkiemchuhang();
                    tk.ShowDialog();
                    makhachhang = tk._smachuhang;
                    break;
                case "frm_timkiemnhanvien":
                    frm_timkiemnhanvien frm = new frm_timkiemnhanvien();
                    frm.ShowDialog();
                    manv = frm.manhanvien;
                    break;
                case "frm_timkiemhanghoa":
                    frm_timkiemhanghoa frm1 = new frm_timkiemhanghoa();
                    frm1.ShowDialog();
                    mahanghoa = frm1._mahanghoa;
                    break;
              

               
            }
        }
        //public void ShowFormTimChuHang()
        //{
             
        //            frm_timkiemchuhang tk = new frm_timkiemchuhang();
        //            tk.ShowDialog();
        //            makhachhang = tk._smachuhang;
                   
        //}
        //public void ShowFormTimNhanVien()
        //{

        //    frm_timkiemnhanvien frm = new frm_timkiemnhanvien();
        //    frm.ShowDialog();
        //    manv = frm.manhanvien;

        //}
        //public void ShowFormTimHangHoa()
        //{
        //    frm_timkiemhanghoa frm = new frm_timkiemhanghoa();
        //    frm.ShowDialog();
        //    mahanghoa = frm._mahanghoa;
        //}
        //public void ShowFormLayDuLieuBanCan()
        //{
        //    frm_bancan frm = new frm_bancan();
        //    frm.Show();
        //    strongluong = frm._result;

        //}
        public DataTable IEnumerabletoDataTable(IEnumerable IEN)
        {
            DataTable dt = new DataTable();
            
            foreach (object obj in IEN)
            {
                Type t = obj.GetType();
                PropertyInfo[] pis = t.GetProperties();
                foreach (PropertyInfo pi in pis)
                {
                    if (!dt.Columns.Contains(pi.Name))
                    {
                        dt.Columns.Add(pi.Name);
                    }
                }
                DataRow dr = dt.NewRow();
                foreach (PropertyInfo pi in pis)
                {
                    object value = pi.GetValue(obj, null);
                    dr[pi.Name] = value;
                }
                dt.Rows.Add(dr);

            }

            return dt;

        }
    }
}
